Fetch a new token when opting into beta updates
parent
cad332ee3d
commit
7cccaa4130
|
@ -3,6 +3,7 @@
|
|||
* Refactor Syncing to not make unnecessary HTTP requests.
|
||||
* Estop status is now much faster.
|
||||
* Add dns checkup for users with factory resetting disabled to make tokens refresh faster.
|
||||
* Opting into beta updates will refresh farmbot's token.
|
||||
|
||||
# 6.1.2
|
||||
* Fix fw hardware being reset on os upgrade.
|
||||
|
|
|
@ -26,6 +26,7 @@ defmodule Farmbot.System.ConfigStorage.Dispatcher do
|
|||
end
|
||||
|
||||
def handle_call({:dispatch, group, key, val}, _, state) do
|
||||
Farmbot.System.Registry.dispatch(:config_storage, {group, key, val})
|
||||
{:reply, :ok, [{:config, group, key, val}], state}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,7 @@ defmodule Farmbot.System.UpdateTimer do
|
|||
|
||||
def init([]) do
|
||||
spawn __MODULE__, :wait_for_http, [self()]
|
||||
Farmbot.System.Registry.subscribe(self())
|
||||
{:ok, [], :hibernate}
|
||||
end
|
||||
|
||||
|
@ -34,4 +35,13 @@ defmodule Farmbot.System.UpdateTimer do
|
|||
Process.send_after(self(), :checkup, @twelve_hours)
|
||||
{:noreply, state, :hibernate}
|
||||
end
|
||||
|
||||
def handle_info({Farmbot.System.Registry, {:config_storage, {"settings", "os_auto_update", true}}}, state) do
|
||||
Farmbot.Bootstrap.AuthTask.force_refresh()
|
||||
{:noreply, state, :hibernate}
|
||||
end
|
||||
|
||||
def handle_info({Farmbot.System.Registry, _}, state) do
|
||||
{:noreply, state, :hibernate}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
defmodule Farmbot.System.UpdateTimerTest do
|
||||
use ExUnit.Case, async: false
|
||||
alias Farmbot.System.ConfigStorage
|
||||
|
||||
test "Opting into beta updates should refresh token" do
|
||||
Farmbot.System.Registry.subscribe(self())
|
||||
|
||||
old = ConfigStorage.get_config_value(:string, "authorization", "token")
|
||||
|
||||
ConfigStorage.update_config_value(:bool, "settings", "os_auto_update", false)
|
||||
ConfigStorage.update_config_value(:bool, "settings", "os_auto_update", true)
|
||||
|
||||
assert_receive {Farmbot.System.Registry, {:config_storage, {"settings", "os_auto_update", true}}}
|
||||
assert_receive {Farmbot.System.Registry, {:authorization, :new_token}}, 1000
|
||||
|
||||
new = ConfigStorage.get_config_value(:string, "authorization", "token")
|
||||
assert old != new
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue